﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace POVRay {
    public struct Vector3 {
        public float X, Y, Z;

        public Vector3(float x, float y, float z) {
            this.X = x;
            this.Y = y;
            this.Z = z;
        }

        public static Vector3 operator -(Vector3 v) {
            return new Vector3(-v.X, -v.Y, -v.Z);
        }

        public static Vector3 operator +(Vector3 v1, Vector3 v2) {
            return new Vector3(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
        }

        public static Vector3 operator -(Vector3 v1, Vector3 v2) {
            return new Vector3(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
        }

        public static Vector3 operator *(Vector3 v, float scale) {
            return new Vector3(v.X * scale, v.Y * scale, v.Z * scale);
        }

        public static float Distance(Vector3 v1, Vector3 v2) {
            float dx = v1.X - v2.X;
            float dy = v1.Y - v2.Y;
            float dz = v1.Z - v2.Z;
            return (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
        }

        public static void Distance(ref Vector3 v1, ref Vector3 v2, out float result) {
            float dx = v1.X - v2.X;
            float dy = v1.Y - v2.Y;
            float dz = v1.Z - v2.Z;
            result = (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
        }

        public override string ToString() {
            if (X == Y && Y == Z) {
                return X.POVRayString();
            } else {
                return "<" + X.POVRayString() + ", " + Y.POVRayString() + ", " + Z.POVRayString() + ">";
            }
        }
    }
}
